package com.ct.deadlockdetetor.controller;

import com.ct.deadlockdetetor.common.controller.BaseController;
import com.ct.deadlockdetetor.common.pojo.CommonResult;
import com.ct.deadlockdetetor.common.pojo.TableDataInfo;
import com.ct.deadlockdetetor.domain.resource.dto.ResourceAddDTO;
import com.ct.deadlockdetetor.domain.resource.dto.ResourceQueryDTO;
import com.ct.deadlockdetetor.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/resource")
public class ResourceController extends BaseController {

    @Autowired
    private ResourceService resourceService;

    /**
     * 注册资源
     */
    @PostMapping("/register")
    public CommonResult<Void> register(@Validated @RequestBody ResourceAddDTO resourceAddDTO) {
        return toCommonResult(resourceService.register(resourceAddDTO));
    }

    /**
     * 删除资源
     */
    @DeleteMapping("/delete")
    public CommonResult<Void> delete(Integer resourceId) {
        return toCommonResult(resourceService.delete(resourceId));
    }

    /**
     * 查看资源列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ResourceQueryDTO resourceQueryDTO) {
        return getTableDataInfo(resourceService.list(resourceQueryDTO));
    }
}
